{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "if __name__ == '__main__':\n",
    "    friend_pairs = {}\n",
    "    for row in sys.stdin:\n",
    "        if row.strip() != \"\":\n",
    "            person = row[0]\n",
    "            friends = list(row[1:].strip())\n",
    "            for i in range(len(friends)):\n",
    "                for j in range(1, len(friends)):\n",
    "                    if person not in friend_pairs.keys():\n",
    "                        pairs_set = set()\n",
    "                        pairs_set.add(friends[i])\n",
    "                        pairs_set.add(friends[j])\n",
    "                        friend_pairs[person] = pairs_set\n",
    "                    else:\n",
    "                        pairs_set = friend_pairs[person]\n",
    "                        pairs_set.add(friends[i])\n",
    "                        pairs_set.add(friends[i])\n",
    "\n",
    "    for k in friend_pairs:\n",
    "        print(k, friend_pairs[k])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
